package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        if(bookList.getUsedSize() == 0) {
            System.out.println("目前暂时没有图书，请稍后过来查看...");
            return;
        }
        System.out.println("借阅图书...");
        Scanner in = new Scanner(System.in);
        System.out.println("请输入要查询的书名：");
        String name = in.nextLine();
        Book book;

        while((book = bookList.findBookOfName(name)) == null) {
            System.out.println("未找到图书，请重新输入：");
            name = in.nextLine();
        }
        if(book.isBorrow()) {
            System.out.println("该图书已经借出");
        } else {
            book.setBorrow(true);
            System.out.println("借阅成功！！！");
        }
    }
}
